﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
namespace SQT.tracnghiem.Ajax.ASP.Lesson
{
    public partial class change_area : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int id = int.Parse(Request.Form["id"]);
            string area = Request.Form["area"];

            if (area.IndexOf(',') != -1)
            {
                string[] split = new string[area.Split(',').Length];

                TblLessonWordCollection col_word = new TblLessonWordController().FetchAll();
                split = area.Split(',');
                var get_word1 = new TblLessonWordController().FetchAll().Where(x => x.LessonId == id).ToList();
                for (int i = 0; i < get_word1.Count;i++)
                {
                    var get_word = new TblLessonWordController().FetchAll().Where(x => x.LessonId == id).ToList();
                    if (get_word[i].WordId != int.Parse(split[i]))
                    {
                        var get_change = col_word.Where(x => x.WordId == int.Parse(split[i])).Single();
                        new TblLessonWordController().Update(get_word[i].WordId, null, get_change.WordName, get_change.WordType, get_change.WordChinese, get_change.WordChineseMean, get_change.WordVietNamMean);
                    }
                }
            }
        }

    }
}